package com.hr.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hr.entity.AoaNoticeList;
import com.hr.service.AoaNoticeListService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * (AoaNoticeList)表控制层
 *
 * @author makejava
 * @since 2022-06-19 14:19:23
 */
@RestController
@RequestMapping("aoaNoticeList")
public class AoaNoticeListController {
    /**
     * 服务对象
     */
    @Resource
    private AoaNoticeListService aoaNoticeListService;

//    /**
//     * 三表联查，aoa_notice_list，aoa_user，aoa_dept，公告页面
//     * @return
//     */
//    @GetMapping("/queryListAll")
//    public List<AoaNoticeList> queryListAll(Page<AoaRole> page){
//        List<AoaNoticeList> list = aoaNoticeListService.queryListAll(page);
//        System.out.println("list"+list);
//        return list;
//    }

    /**
     * 查询全部（带分页的）
     * @param page
     * @return
     */
    @GetMapping("/queryList")
    public Page<AoaNoticeList> queryList(Page<AoaNoticeList> page) {
        page=aoaNoticeListService.queryList(page);
        System.out.println(page);
        return page;
    }

    /**
     * 添加公告
     * @param aoaNoticeList
     * @return
     */
    @PostMapping("/add")
    public ResponseEntity<String> add(@RequestBody AoaNoticeList aoaNoticeList){
        //添加一个发布时间
        aoaNoticeList.setNoticeTime(new Date());
        //添加
        boolean b = aoaNoticeListService.save(aoaNoticeList);
        //判断是否添加成功
        if(b){
            return ResponseEntity.ok("添加成功");
        }else{
            return ResponseEntity.ok("添加失败");
        }
    }

    /**
     * 根据 id 删除
     * @param noticeId
     * @return
     */
    @DeleteMapping("/deleteId")
    public ResponseEntity<String> deleteId(Integer noticeId){
        //根据id删除
        boolean b = aoaNoticeListService.removeById(noticeId);
        //判断是否删除成功
        if(b){
            return ResponseEntity.ok("删除成功");
        }else{
            return ResponseEntity.ok("删除失败");
        }
    }

    /**
     * 根据id查询
     * @param noticeId
     * @return
     */
    @GetMapping("/queryById")
    public AoaNoticeList queryById(Integer noticeId){
        AoaNoticeList aoaNoticeList = aoaNoticeListService.queryById(noticeId);
        return aoaNoticeList;
    }

    /**
     * 根据 id 修改
     * @param aoaNoticeList
     * @return
     */
    @PostMapping("/updateId")
    public ResponseEntity<String> updateId(@RequestBody AoaNoticeList aoaNoticeList){
        //修改时间
        aoaNoticeList.setModifyTime(new Date());
        //根据 id 修改
        boolean b = aoaNoticeListService.updateById(aoaNoticeList);
        //判断是否修好成功
        if(b){
            return ResponseEntity.ok("修改成功");
        }else{
            return ResponseEntity.ok("修改失败");
        }
    }

    @GetMapping("/queryMax")
    public Integer queryMax(){
        int i = aoaNoticeListService.queryMax();
        System.out.println("i"+i);
        return i;
    }
}

